package logs

import (
	"bytes"
	"log"
	"strings"
)

type Formatter func(e *Entity, msg string) string

func DefaultFormat(e *Entity, msg string) string {
	writer := bytes.NewBuffer(nil)
	if len(e.Tag) > 0 {
		tag := strings.Join(e.Tag, "][")
		msg = tag[1:len(tag)-1] + " " + msg
	}
	prefix := ""
	if len(e.Name) > 0 {
		prefix = "[" + e.Name + "]"
	}
	_ = log.New(writer, prefix, log.Ldate|log.Ltime|log.Lshortfile).Output(e.Level, msg)
	return writer.String()
}
